package com.amado.course27.service.impl;


import java.util.ArrayList;
import java.util.List;

import com.amado.course27.dao.AllDao;
import com.amado.course27.entity.Goods;
import com.amado.course27.service.GoodsService;

public class GoodsServiceImpl implements GoodsService{
	public List goodsArray = new ArrayList();

	public GoodsServiceImpl(){
		goodsArray.add(new Goods("goodsCode001", "打球", "v001_001", 1000, "张三"));
		goodsArray.add(new Goods("goodsCode002", "跑步", "v001_001", 1000, "张三"));

		Goods  goods = (Goods)goodsArray.get(1);
		goods.getGoodsCode();
	}


	@Override
	public Goods getGoods(String goodsCode) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public void addGoods(Goods goods) {
		goodsArray.add(goods);	}

	@Override
	public void updateGoods(Goods goods) {
		if(goods==null){
			return;
		}
		Goods returnGoods = getGoods(goods.getGoodsCode());
		if(returnGoods==null){
			System.out.println("不存在");
		}else{
			returnGoods.setName(goods.getName());
			returnGoods.setPrice(goods.getPrice());
		}
	}
	
	@Override
	public Goods[] listGoods() {
		return (Goods[])goodsArray.toArray();
	}

	@Override
	public Goods[] listGoods(String goodsName) {
//		List<Goods> listGoods = new ArrayList();
		Goods[] newGoodsArray = new Goods[100];
		int count =0;
		for(Object goods:goodsArray){
			if(goods!=null && ((Goods)goods).getName().indexOf(goodsName)!=-1){
				newGoodsArray[count++]=(Goods)goods;
			}
		}
		return newGoodsArray;
	}
	public Goods[] listGoods(String goodsName,String catelogType) {
//		List<Goods> listGoods = new ArrayList();
		Goods[] newGoodsArray = new Goods[100];
		int count =0;
		for(Object goods:goodsArray){
			if(goods!=null && ((Goods)goods).getName().indexOf(goodsName)!=-1){
				newGoodsArray[count++]=(Goods)goods;
			}
		}
		return newGoodsArray;
	}

	@Override
	public boolean deleteGoods(String goodsCode) {
		return false;
	}
}
